﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CCH.DAO;
using CCH.Entity;


public partial class login : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!this.IsPostBack)
        {
            this.Session.RemoveAll();

            this.ImageButton1.Attributes.Add("onmouseout", "MM_swapImgRestore()");
            this.ImageButton1.Attributes.Add("onmouseover", "MM_swapImage('ImageButton1','','image/login/login-05-1.gif',1)");

            this.ImageButton2.Attributes.Add("onmouseout", "MM_swapImgRestore()");
            this.ImageButton2.Attributes.Add("onmouseover", "MM_swapImage('ImageButton2','','image/login/login-06-1.gif',1)");
        }
        
    }
    protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
    {
        if (string.IsNullOrEmpty(this.tbox_id.Text) || string.IsNullOrEmpty(this.tbox_pw.Text))
        {
            JsUtil.AlertJs(this, "請輸入帳號或密碼!!");
        }
        else
        {
            peopleDAO dao = new peopleDAO();
            people user = dao.Get_people(this.tbox_id.Text, this.tbox_pw.Text);

            if (user == null)
            {
                JsUtil.AlertJs(this, "帳號或密碼錯誤!!");
            }
            else
            {
                SessionObject sessionObj = new SessionObject();
                sessionObj.SessionUserID = user.peo_uid;
                sessionObj.SessionUserName = user.peo_name;
                sessionObj.SessionUserLogin = true;

                Response.Redirect("10/1001.aspx");
            }
        }
    }

    protected void ImageButton2_Click(object sender, ImageClickEventArgs e)
    {
        this.tbox_id.Text = "";
        this.tbox_pw.Text = "";
    }
}